今天是練習cpe的All You Need Is Love題目
#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y)
{
while((x%=y) && (y%=x))
{
}
return x+y;
}
int num=1;
int main()
{
int N;
string S ,L;
cin >> N;
while(N--)
{
cin >> S >> L;
int s1=0;
int s2=0;
for(int i = 0 ;i<S.length();i++)
{
s1 *= 2;
s1 += S[i] - '0';
}
for(int i = 0 ;i<L.length();i++)
{
s2 *= 2;
s2 += L[i] - '0';
}
cout << "Pair #" << num++ << ": ";
if(gcd(s1 ,s2) > 1)
{
cout << "All you need is love!" << endl;
}
else
{
cout << "Love is not all you need" << endl;
}
}
return 0;
}
int gcd(int x, int y)
{
while((x%=y) && (y%=x))
{
}
return x+y;
}
int s1=0;
int s2=0;
for(int i = 0 ;i<S.length();i++)
{
s1 *= 2;
s1 += S[i] - '0';
}
for(int i = 0 ;i<L.length();i++)
{
s2 *= 2;
s2 += L[i] - '0';
}